import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AKapi.settings.dev')
import django
django.setup()
# 必须建一个叫celery.py文件
from datetime import timedelta, datetime

from celery import Celery
from celery.schedules import crontab

broker = 'redis://127.0.0.1:6379/1'  # 任务队列
backend = 'redis://127.0.0.1:6379/0'  # 存储结果的库


app = Celery(main=__name__, backend=backend, broker=broker, include=['celery_task.home_task', ])
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC时间
app.conf.enable_utc = False

# 3）添加任务：自动添加任务，所以要启动一个添加任务的服务
# 命令：celery beat -A celery_task -l info
app.conf.beat_schedule = {
    'add_task': {
        'task': 'celery_task.home_task.banner_update',  # 指定task任务
        'schedule': timedelta(seconds=10),  # 每隔3秒执行一次
        # 'schedule': crontab(hour=8, day_of_week=1),  # 每周1早八点执行
        'args': (),
    }
}